package com.gmcc.aiquality.webadmin.upms.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.gmcc.aiquality.webadmin.upms.dao.TaskProjectMapper;
import com.gmcc.aiquality.webadmin.upms.model.DataCollectionTask;
import com.gmcc.aiquality.webadmin.upms.model.Project;
import com.gmcc.aiquality.webadmin.upms.model.TaskProject;
import com.gmcc.aiquality.webadmin.upms.service.DataCollectionTaskService;
import com.gmcc.aiquality.webadmin.upms.service.TaskProjectService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;
import java.util.List;

@Slf4j
@Service("taskProjectService")
public  class TaskProjectServiceImpl implements TaskProjectService{
    @Autowired
    private DataCollectionTaskService dataCollectionTaskService;
    @Autowired
    private TaskProjectMapper taskProjectMapper;
    @Override
    @Transactional(rollbackFor = Exception.class)
    public void add(List<Project> projectList) {
        for (Project project : projectList) {
            TaskProject taskProject = new TaskProject();
            String taskId = "";
            //生成一个时间戳
            //区分本地文件和云端文件
            String projectFile = project.getProjectFile();
            String startStr= "";
            if (projectFile.equals("本地")) {
                startStr = "bendi";
            } else {
                startStr ="yunduan";
            }
            taskId = String.valueOf(System.currentTimeMillis());
            taskProject.setProjectId(project.getProjectCode());
            taskProject.setTaskId(startStr+taskId);
            taskProjectMapper.add(taskProject);

            //添加ai质检任务
            DataCollectionTask dataCollectionTask = new DataCollectionTask();
            dataCollectionTask.setTaskId(startStr+taskId);
            dataCollectionTask.setProjectCode(project.getProjectCode());
            dataCollectionTask.setTaskType(project.getProjectType());
            dataCollectionTask.setTaskStatus(project.getProjectStatus());
            dataCollectionTask.setTaskCreator(project.getCreateName());
//            dataCollectionTask.setCreateTime(new Date());
//            dataCollectionTask.setCreateTime(project.getCreateDate());
//            dataCollectionTask.setFinishTime(project.getSyncAt());
//            dataCollectionTask.setResult("");
//            dataCollectionTask.setTaskContent("");
//            dataCollectionTask.setDataCollectionStatus("未开始");
//            dataCollectionTask.setAiQualityStatus("未开始");

            dataCollectionTaskService.add(dataCollectionTask);
        }
    }

}
